package com.betterjr.modules.application;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.web.ControllerExceptionHandler;
import com.betterjr.common.web.ControllerExceptionHandler.ExceptionHandler;
import com.betterjr.common.web.Servlets;

@Controller
@RequestMapping(value = "/Platform/ApplicationOperator")
public class ApplicationOperatorController {

    private static final Logger logger = LoggerFactory.getLogger(ApplicationOperatorController.class);

    @Reference(interfaceClass = IApplicationOperatorService.class)
    private IApplicationOperatorService applicationOperatorService;

    /**
     * 
     * @Title: queryApplicationsCurrentUser 
     * @Description:查询个人定制信息 
     * @param request
     * @param operatorId
     * @param businStatus  状态 1未生效 2已生效 9已失效
     * @return应用列表集合
     * @throws 
     * @author xuyp
     * @date 2017年11月30日 下午2:24:44
     * filterFalg
     */
    @RequestMapping(value = "/queryApplicationsCurrentUser", method = RequestMethod.POST)
    public @ResponseBody String queryApplicationsCurrentUser(final HttpServletRequest request, Long operatorId,
            String businStatus) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationOperatorService.webQueryApplicationsCurrentUser(businStatus, operatorId, anMap);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: saveAddOrUpdateApplicationOperator 
     * @Description: 新增或者更新个人定制应用
     * @param request
     * @return 插入的应用
     * @throws 
     * @author xuyp
     * @date 2017年11月30日 下午2:26:13
     * 
     * applicationId
     * filterfalg    是否拦截  1 默认不拦截   2 拦截
     * proprity   是否是个性定制应用   1 是   2 不是
     * proprityLevel  个性定制显示的优先级 越小越优先
     */
    @RequestMapping(value = "/saveAddOrUpdateApplicationOperator", method = RequestMethod.POST)
    public @ResponseBody String saveAddOrUpdateApplicationOperator(final HttpServletRequest request) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationOperatorService.webSaveAddOrUpdateApplicationOperator(anMap);
            }
        }, "操作失败", logger);
    }
}
